// 三测单数据集合
<template>
  <van-nav-bar
    :title="title"
    left-text="返回"
    left-arrow
    @click-left="onClickLeft"
  >
    <template #right>
      <van-icon name="wap-nav" @click="tolist" />
    </template>
  </van-nav-bar>
  <!-- 表头 -->
  <van-cell>
    <template #title>
      <van-row>
        <van-col span="4">日期</van-col>
        <van-col span="4">时间点</van-col>
        <van-col span="6">类别</van-col>
        <van-col span="7">检查值</van-col>
        <van-col span="3">管理</van-col>
      </van-row>
    </template>
  </van-cell>

  <!-- 表格内容 -->
  <van-cell-group>
    <van-cell v-for="(item, index) in list" :key="index">
      <template #title>
        <van-row>
          <!-- 添加 offset 控制左侧间距 -->
          <van-col span="4" offset="0">{{ item.measuredate }}</van-col>
          <van-col span="4" offset="0">{{ item.timepoint }}</van-col>
          <van-col span="6" offset="0">{{ item.type }}</van-col>
          <van-col span="7" offset="0">{{ item.value + item.unit }}</van-col>
          <van-col span="3" offset="0">
            <van-button size="mini" @click="handledel(item)">删除</van-button>
          </van-col>
        </van-row>
      </template>
    </van-cell>
  </van-cell-group>
</template>

<script setup>
import { useRoute, useRouter } from "vue-router";
import { querylist, deletebyid } from "../api/sign";
import { reactive, ref, onMounted } from "vue";
import dayjs from "dayjs";
const router = useRouter();
const selectitem = JSON.parse(localStorage.getItem("selectitem"));
const title = selectitem.name + selectitem.age + "岁";
function onClickLeft() {
  console.log("onClickLeft");
  // this.$router.go(-1)
  router.go(-1);
}
function tolist() {
  router.push("/");
}

const list = reactive([]);
onMounted(() => {
  querylist({
    page: {
      current: 1,
      size: -1,
    },
    sign: {
      patientregid: selectitem.id,
    },
  }).then((res) => {
    console.log(res.data);
    list.push(...res.data);
  });
});

function handledel(item) {
  console.log(item);
  deletebyid(item).then((res) => {
    console.log(res);
    list.splice(list.indexOf(item), 1);
  });
}
function formatDate(date) {
  return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
}
</script>

<style></style>
